/*
 * LDIR
 *
 * LDIR, a GPS cartography application built for Let's Do It Romania eco
 * campaign.
 * Copyright (C) 2010 Genera Software <office@generasoftware.com>
 *
 * http://generasoftware.com/
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 */
#ifndef SETTINGS_H
#define SETTINGS_H

// INCLUDES
#include <coemain.h>
#include "Interfaces.h"
#include "Events.h"

class CWasteCache;
class CWasteInfo;

const TUid KSettingsUID =
	{
	0x28e46458
	};

// CLASS DECLARATION

/**
 *  CSettings
 *
 */
class CSettings : public CCoeStatic, public MSerializable
	{

public:
	// EVENTS
	TEvent0<void> SettingsChanged;

public:
	// Constructors and destructor

	/**
	 * Destructor.
	 */
	~CSettings();

	/**
	 * Two-phased constructor.
	 */
	static CSettings& InstanceL();
	const TDesC& SplashFile();
	const TDesC& AppDir();
	const TDesC& ResourceDir();
	const TDesC& MifFile();
	const TDesC& Imei();
	const TDesC& UserSalt();
	void SetUserSalt( const TDesC& aUserSalt );
	void StoreSettingsL();
	void LoadSettingsL();
	TBool IsFirstRun();
	void ClearIsFirstRunL();
	TInt32 Iap();
	void SetIap( const TInt32& aValue );
	TDes& Username();
	void SetUsername( const TDesC& aUsername );
	TDes& Password();
	void SetPassword( const TDesC& aPassword );

	HBufC8* GenerateAuthStringLC();
	HBufC8* GeneratePassHashLC();

	CWasteCache& PendingUploadCache();
	CWasteCache& LocalCache();
	CWasteInfo* WorkingWaste();
	void SetWorkingWaste( CWasteInfo* aWasteInfo );
	
public:
	// From MSerializable
	void ExternalizeL( RWriteStream& aStream ) const;
	void InternalizeL( RReadStream& aStream );

private:

	/**
	 * Constructor for performing 1st stage construction
	 */
	CSettings();

	/**
	 * EPOC default constructor for performing 2nd stage construction
	 */
	void ConstructL();

private:
	TBool iIsFirstRun;

	TBool iAutologin;
	TPath iAppDir;
	TPath iResourceDir;
	TFileName iStorageName;
	TFileName iSplash;
	TFileName iMifFile;
	TBuf<20> iImei;
	TBuf<KMaxName> iUsername;
	TBuf<KMaxName> iPassword;
	TBuf<KMaxName> iUserSalt;
	TInt32 iIap;
	CWasteCache* iPendingUploadCache;
	CWasteCache* iLocalCache;
	CWasteInfo* iCurrentWasteInfo;
	};

#endif // SETTINGS_H
